<?php
	$_ig_lightbox_config_general = Mage::getStoreConfig('ig_lightbox/general');
	$_ig_lightbox_config_display = Mage::getStoreConfig('ig_lightbox/display');
	$_ig_lightbox_config_effects = Mage::getStoreConfig('ig_lightbox/effects');

	/* Read configuration */
	list($_ig_lightbox_main_width, $_ig_lightbox_main_height)	= split('x', $_ig_lightbox_config_general['mainImageSize']);
	list($_ig_lightbox_thu_width, $_ig_lightbox_thu_height)		= split('x', $_ig_lightbox_config_general['thumbnailImageSize']);
	list($_ig_lightbox_big_width, $_ig_lightbox_big_height)		= split('x', $_ig_lightbox_config_general['bigImageSize']);

	$_ig_lightbox_background_opactiy	= floatval($_ig_lightbox_config_display['backgroundOpacity']);
	$_ig_lightbox_imagebox_opactiy		= floatval($_ig_lightbox_config_display['imageboxOpacity']);
	$_ig_lightbox_toolbar_opactiy		= floatval($_ig_lightbox_config_display['toolbarOpacity']);
	
	$_ig_lightbox_background_color		= $_ig_lightbox_config_display['backgroundColor'];
	$_ig_lightbox_imagebox_color		= $_ig_lightbox_config_display['imageboxColor'];
	$_ig_lightbox_toolbar_color			= $_ig_lightbox_config_display['toolbarColor'];
	$_ig_lightbox_toolbar_text_color	= $_ig_lightbox_config_display['toolbarTextColor'];
	$_ig_lightbox_toolbar_text_font		= $_ig_lightbox_config_display['toolbarTextFont'];
	$_ig_lightbox_toolbar_text_size		= intval($_ig_lightbox_config_display['toolbarTextSize']);
	
	$_ig_lightbox_border_color		= $_ig_lightbox_config_display['borderColor'];
	$_ig_lightbox_border_size		= intval($_ig_lightbox_config_display['borderSize']);

	$_ig_padding_size				= intval($_ig_lightbox_config_display['paddingSize']);
	
	$_ig_lightbox_fade_in_duration			= floatval($_ig_lightbox_config_effects['fadeIn']);
	$_ig_lightbox_fade_out_duration			= floatval($_ig_lightbox_config_effects['fadeOut']);
	$_ig_lightbox_image_swap_duration		= floatval($_ig_lightbox_config_effects['imageSwap']);
	$_ig_lightbox_image_resize_duration		= floatval($_ig_lightbox_config_effects['imageResize']);

	/* Default values and ranges */
	$_ig_lightbox_main_width	= intval($_ig_lightbox_main_width)	> 0	? intval($_ig_lightbox_main_width)	: 800;
	$_ig_lightbox_main_height	= intval($_ig_lightbox_main_height)	> 0 ? intval($_ig_lightbox_main_height)	: 600;
	$_ig_lightbox_thu_width		= intval($_ig_lightbox_thu_width)	> 0	? intval($_ig_lightbox_thu_width)	: 256;
	$_ig_lightbox_thu_height	= intval($_ig_lightbox_thu_height)	> 0	? intval($_ig_lightbox_thu_height)	: 256;
	$_ig_lightbox_big_width		= intval($_ig_lightbox_big_width) 	> 0	? intval($_ig_lightbox_big_width)	: 60;
	$_ig_lightbox_big_height	= intval($_ig_lightbox_big_height) 	> 0	? intval($_ig_lightbox_big_height)	: 60;
	
	$_ig_lightbox_background_color		= $_ig_lightbox_background_color	? $_ig_lightbox_background_color	: '#000000';
	$_ig_lightbox_imagebox_color		= $_ig_lightbox_imagebox_color		? $_ig_lightbox_imagebox_color		: '#000000';
	$_ig_lightbox_toolbar_color			= $_ig_lightbox_toolbar_color		? $_ig_lightbox_toolbar_color		: '#000000';
	$_ig_lightbox_toolbar_text_color	= $_ig_lightbox_toolbar_text_color	? $_ig_lightbox_toolbar_text_color	: '#000000';
	$_ig_lightbox_toolbar_text_font		= $_ig_lightbox_toolbar_text_font	? $_ig_lightbox_toolbar_text_font	: 'Verdana';
	$_ig_lightbox_border_color			= $_ig_lightbox_border_color		? $_ig_lightbox_border_color		: '#000000';
	
	$_ig_lightbox_toolbar_text_size		= intval($_ig_lightbox_toolbar_text_size) 	> 0		? intval($_ig_lightbox_toolbar_text_size)	: 10;
	$_ig_lightbox_border_size			= intval($_ig_lightbox_border_size) 		>= 0	? intval($_ig_lightbox_border_size)	: 0;
	
	$_ig_lightbox_background_opactiy	= min(1.0, max(0.0, $_ig_lightbox_background_opactiy));
	$_ig_lightbox_imagebox_opactiy		= min(1.0, max(0.0, $_ig_lightbox_imagebox_opactiy));
	$_ig_lightbox_toolbar_opactiy		= min(1.0, max(0.0, $_ig_lightbox_toolbar_opactiy));
?>

<script type="text/javascript">
	ig_lightbox_img_border				= <?php echo $_ig_padding_size ?>;
	ig_lightbox_background_opactiy		= <?php echo $_ig_lightbox_background_opactiy ?>;
	ig_lightbox_imagebox_opactiy		= <?php echo $_ig_lightbox_imagebox_opactiy ?>;
	ig_lightbox_toolbar_opactiy			= <?php echo $_ig_lightbox_toolbar_opactiy ?>;
	ig_lightbox_background_color		= "<?php echo $_ig_lightbox_background_color ?>";
	ig_lightbox_imagebox_color			= "<?php echo $_ig_lightbox_imagebox_color ?>";
	ig_lightbox_toolbar_color			= "<?php echo $_ig_lightbox_toolbar_color ?>";
	ig_lightbox_toolbar_text_color		= "<?php echo $_ig_lightbox_toolbar_text_color ?>";
	ig_lightbox_toolbar_text_font		= "<?php echo $_ig_lightbox_toolbar_text_font ?>";
	ig_lightbox_toolbar_text_size		= <?php echo $_ig_lightbox_toolbar_text_size ?>;
	ig_lightbox_border_size				= <?php echo $_ig_lightbox_border_size ?>;
	ig_lightbox_border_color			= "<?php echo $_ig_lightbox_border_color ?>";
	
	ig_lightbox_fade_in_duration		= <?php echo $_ig_lightbox_fade_in_duration ?>;
	ig_lightbox_fade_out_duration		= <?php echo $_ig_lightbox_fade_out_duration ?>;
	ig_lightbox_image_swap_duration		= <?php echo $_ig_lightbox_image_swap_duration ?>;
	ig_lightbox_image_resize_duration	= <?php echo $_ig_lightbox_image_resize_duration ?>;
</script>

<div id="ig-lightbox-back"></div>
<div id="ig-lightbox-image"></div>
<img id="ig-lightbox-image-src" /></img>
<table id="ig-lightbox-image-commands">
	<tbody>
		<tr>
			<td style="text-align: center" width="64"><a href="#" onclick="ig_lightbox_prev()"><img src="<?php echo $this->getSkinUrl('images/ig_lightbox/prev.png') ?>" alt="prev" /></a></td>
			<td id="ig-lightbox-image-commands-label-td"><div id="image-label"></div></td>
			<td style="text-align: center" width="64"><a href="#" onclick="ig_lightbox_next()"><img src="<?php echo $this->getSkinUrl('images/ig_lightbox/next.png') ?>" alt="next" /></a></td>
		</tr>
	</tbody>
</table>
<div id="ig-lightbox-image-close"><a href="#" onclick="ig_lightbox_hide()"><img id="ig-lightbox-image-close-img" src="<?php echo $this->getSkinUrl('images/ig_lightbox/close.png') ?>" alt="close" /></a></div>

<?php
	$_ig_lightbox_images_count = 0;
	
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
?>

<a href="#" onclick="ig_lightbox_show(0)">
<?php
	$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image')->keepFrame(false)->resize($_ig_lightbox_main_width, $_ig_lightbox_main_height).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
	echo $_helper->productAttribute($_product, $_img, 'image')
?>
</a>

<?php
	$js_load=array();
	if (count($this->getGalleryImages()) > 0)
	{
?>
<div class="more-views">
    <h4><?php echo $this->__('More Views') ?></h4>
    <ul>
    <?php
    	foreach ($this->getGalleryImages() as $_image)
    	{
    		$src=$this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->constrainOnly(true)->keepFrame(false)->resize($_ig_lightbox_big_width, $_ig_lightbox_big_height);
    		$lbl=$this->htmlEscape($_image->getLabel());
    		
    		array_push($js_load, "ig_lightbox_img_sequence.push('$src');");
			array_push($js_load, "ig_lightbox_img_labels.push('$lbl');");
    ?>
        <li>
        	<a href="#" onclick="ig_lightbox_show('<?php echo $_ig_lightbox_images_count; ?>')">
        		<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->keepFrame(true)->resize($_ig_lightbox_thu_width, $_ig_lightbox_thu_height); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
        	</a>
        </li>
    <?php
    		$_ig_lightbox_images_count++;
    	}
    ?>
    </ul>
</div>
<?php } ?>

<script type="text/javascript">
	Event.observe(window, 'load', function() {
 		<?php foreach ($js_load as $line) echo "$line\n" ?>
	});
</script>
